home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / www / src / print-www / get-http-document next >
Encoding:
Text File  |  1992-11-04  |  1.6 KB  |  59 lines

  1. #!/usr/local/bin/perl
  2. #  Obtain a document via HTTP protocol.
  3. # Jim Davis, Nov 4 1992
  4.  
  5.  
  6. ($host,$d) = @ARGV;        # get command line args
  7.  
  8. if ($host eq "") {die "No host supplied.  Stopped";}
  9.  
  10. if ($d eq "") 
  11.  {$i = index ($host, "/");
  12.   if ($i == -1) {die "No document id supplied.  Stopped";}
  13.   $d = substr ($host,$i);
  14.   $host = substr($host,0,$i);}
  15.  
  16. ($host,$port) = split (':',$host);        # separate optional port
  17.  
  18. #print ("Host is ", $host, "\nDoc is ", $d ,"\nPort is ", $port, "\n");
  19.  
  20.  
  21. if ( $port eq "") {$port = 80;}
  22. if ( $port !~ /\d+$/)            # translate symbolic port 
  23.  {($name, $aliases, $nport) = getservbyname($port, 'tcp');
  24.  if ( $nport =~ /\d+$/)
  25.     { $port = $nport;}
  26.    else
  27.     {die "Could not translate port $port to number.  Stopped";}}
  28.  
  29.  
  30. # Can't find this library here, so have to fake it.
  31. #require 'sys/socket.ph';
  32.  
  33. $sockaddr = 'S n a4 x8';         # packing format
  34.  
  35. $hostname = `hostname`;
  36. chop($hostname);                 # get rid of trailing CR
  37. ($name, $aliases, $type, $len, $myaddr) = gethostbyname($hostname);
  38. $here = pack($sockaddr, 2, 0, $myaddr);
  39.  
  40. ($name, $aliases, $type, $len, $destaddr) = gethostbyname($host);
  41.  
  42. #print ("Name = ", $name ," " addr = ", $destaddr, "\n");
  43. if ($destaddr eq "") {die "No such host: $host. Stopped";}
  44.  
  45. $there= pack($sockaddr, 2, $port, $destaddr);
  46.  
  47. ($name, $aliases, $protocol) = getprotobyname('tcp');
  48. socket($S, 2, 1, $protocol) || die "socket: $!";
  49. bind ($S, $here) || die "bind: $!";
  50. connect ($S, $there) || die "connect: $!";
  51.  
  52.  
  53. select($S);
  54. $| = 1;           # force output
  55. print ("GET ", $d ,"\n");
  56. select(STDOUT);
  57. while (<$S>) { print;}
  58.  
  59.